package com.tank.game.core;

import com.tank.game.api.Position;
import com.tank.game.api.Range;
import com.tank.game.api.Shape;

import java.util.Objects;

/**
 * 缺省的范围
 *
 * @author Zed
 */
public class DefaultRange implements Range {

    private Position position;

    private Shape shape;

    public DefaultRange(Builder builder) {
        this.position = Objects.requireNonNull(builder.position, "position cannot be null");
        this.shape = builder.shape;
    }

    @Override
    public Position getPosition() {
        return this.position;
    }

    @Override
    public Shape getShape() {
        return this.shape;
    }

    /**
     * 创建Builder构建器
     *
     * @return {@link Builder}
     */
    public static Builder newBuilder() {
        return new Builder();
    }

    public static final class Builder {
        private Position position;

        private Shape shape;

        /**
         * 位置
         *
         * @param shape {@link Shape}
         * @return {@link Builder}
         */
        public Builder shape(Shape shape) {
            this.shape = shape;
            return this;
        }

        /**
         * 位置
         *
         * @param position {@link Position}
         * @return {@link Builder}
         */
        public Builder position(Position position) {
            this.position = position;
            return this;
        }

        public DefaultRange build() {
            return new DefaultRange(this);
        }
    }
}
